home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / setup.swf / scripts / components / LocalizedLabel.as < prev    next >
Encoding:
Text File  |  2008-10-29  |  5.3 KB  |  192 lines

  1. package components
  2. {
  3.    import flash.text.Font;
  4.    import mx.controls.Label;
  5.    import mx.events.PropertyChangeEvent;
  6.    import mx.styles.StyleManager;
  7.    
  8.    public class LocalizedLabel extends Label
  9.    {
  10.       private static var fontArray:Array = Font.enumerateFonts(false);
  11.       
  12.       private var isFontRetrieved:Boolean = false;
  13.       
  14.       private var defaultAppFontFamily:String;
  15.       
  16.       private var _resourceName:String;
  17.       
  18.       private var _resourceParams:Array;
  19.       
  20.       private var _bundleName:String;
  21.       
  22.       private var _useHTML:Boolean = false;
  23.       
  24.       private var cachedEmbeddedFont:Font;
  25.       
  26.       public function LocalizedLabel()
  27.       {
  28.          super();
  29.       }
  30.       
  31.       private function set _143661260resourceParams(param1:Array) : void
  32.       {
  33.          trace(this.id + " set resourceName: " + this.resourceName);
  34.          this._resourceParams = param1;
  35.          invalidateProperties();
  36.       }
  37.       
  38.       [Bindable(event="propertyChange")]
  39.       public function set resourceName(param1:String) : void
  40.       {
  41.          var _loc2_:Object = this.resourceName;
  42.          if(_loc2_ !== param1)
  43.          {
  44.             this._384566343resourceName = param1;
  45.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceName",_loc2_,param1));
  46.          }
  47.       }
  48.       
  49.       override protected function commitProperties() : void
  50.       {
  51.          var _loc1_:String = null;
  52.          if(this.resourceName)
  53.          {
  54.             _loc1_ = this.localizeText();
  55.             if(this.useHTML)
  56.             {
  57.                htmlText = _loc1_;
  58.             }
  59.             else
  60.             {
  61.                text = _loc1_;
  62.             }
  63.          }
  64.          if(this.useHTML)
  65.          {
  66.             this.ensureGlyphs(htmlText);
  67.          }
  68.          else
  69.          {
  70.             this.ensureGlyphs(text);
  71.          }
  72.          super.commitProperties();
  73.       }
  74.       
  75.       private function set _384566343resourceName(param1:String) : void
  76.       {
  77.          this._resourceName = param1;
  78.          invalidateProperties();
  79.       }
  80.       
  81.       private function set _1377046061bundleName(param1:String) : void
  82.       {
  83.          this._bundleName = param1;
  84.          invalidateProperties();
  85.       }
  86.       
  87.       protected function localizeText() : String
  88.       {
  89.          return LocalizationManager.getInstance().getString(this.resourceName,this.bundleName,this.resourceParams);
  90.       }
  91.       
  92.       override public function initialize() : void
  93.       {
  94.          super.initialize();
  95.       }
  96.       
  97.       [Bindable(event="propertyChange")]
  98.       public function set bundleName(param1:String) : void
  99.       {
  100.          var _loc2_:Object = this.bundleName;
  101.          if(_loc2_ !== param1)
  102.          {
  103.             this._1377046061bundleName = param1;
  104.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"bundleName",_loc2_,param1));
  105.          }
  106.       }
  107.       
  108.       [Bindable(event="propertyChange")]
  109.       public function set useHTML(param1:Boolean) : void
  110.       {
  111.          var _loc2_:Object = this.useHTML;
  112.          if(_loc2_ !== param1)
  113.          {
  114.             this._148395598useHTML = param1;
  115.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"useHTML",_loc2_,param1));
  116.          }
  117.       }
  118.       
  119.       protected function ensureGlyphs(param1:String) : void
  120.       {
  121.          var _loc2_:String = null;
  122.          var _loc3_:Font = null;
  123.          if(!this.isFontRetrieved)
  124.          {
  125.             this.isFontRetrieved = true;
  126.             _loc2_ = getStyle("fontFamily");
  127.             if(_loc2_.match(/,/))
  128.             {
  129.                return;
  130.             }
  131.             for each(_loc3_ in fontArray)
  132.             {
  133.                if(_loc3_.fontName == _loc2_)
  134.                {
  135.                   this.cachedEmbeddedFont = _loc3_;
  136.                   this.defaultAppFontFamily = StyleManager.getStyleDeclaration("Application").getStyle("fontFamily");
  137.                }
  138.             }
  139.          }
  140.          if(this.cachedEmbeddedFont)
  141.          {
  142.             if(!this.cachedEmbeddedFont.hasGlyphs(param1))
  143.             {
  144.                setStyle("fontFamily",this.defaultAppFontFamily);
  145.             }
  146.             else
  147.             {
  148.                setStyle("fontFamily",this.cachedEmbeddedFont.fontName);
  149.             }
  150.          }
  151.       }
  152.       
  153.       [Bindable(event="propertyChange")]
  154.       public function set resourceParams(param1:Array) : void
  155.       {
  156.          var _loc2_:Object = this.resourceParams;
  157.          if(_loc2_ !== param1)
  158.          {
  159.             this._143661260resourceParams = param1;
  160.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceParams",_loc2_,param1));
  161.          }
  162.       }
  163.       
  164.       private function set _148395598useHTML(param1:Boolean) : void
  165.       {
  166.          this._useHTML = param1;
  167.          invalidateProperties();
  168.       }
  169.       
  170.       public function get useHTML() : Boolean
  171.       {
  172.          return this._useHTML;
  173.       }
  174.       
  175.       public function get resourceParams() : Array
  176.       {
  177.          return this._resourceParams;
  178.       }
  179.       
  180.       public function get resourceName() : String
  181.       {
  182.          return this._resourceName;
  183.       }
  184.       
  185.       public function get bundleName() : String
  186.       {
  187.          return this._bundleName;
  188.       }
  189.    }
  190. }
  191.  
  192.